package com.minisoft.utils;

import java.util.regex.Pattern;

public class RedirectFilter {
    public static boolean isWhitelisted2(String url) {
        // 定义白名单正则表达式模式（忽略参数部分）
        String whitelistPattern = "https://qmyx\\.huafacrm\\.com/state\\.html.*|" +
                "https://qmyx-sit\\.huafacrm\\.com/state\\.html.*|" +
                "https://qmyx-uat\\.huafacrm\\.com/state\\.html.*|" +
                "https://[^/]+\\.huafamarkting\\.com/state\\.html.*|" +
                "https://open\\.weixin\\.qq\\.com/connect/oauth2/authorize.*";

        // 使用正则表达式模式进行匹配
        return Pattern.matches(whitelistPattern, url);
    }

    public static boolean isWhitelisted(String url) {
        // 定义白名单正则表达式模式（忽略参数部分）
        String whitelistPattern = "http(s)*://[^/]+\\.huafacrm\\.com/.*|" +
                "https://[^/]+\\.huafamarkting\\.com/.*|" +
                "https://open\\.weixin\\.qq\\.com/connect/oauth2/authorize.*";

        // 使用正则表达式模式进行匹配
        return Pattern.matches(whitelistPattern, url);
    }

    public static void main(String[] args) {
        // 测试示例URL是否在白名单中（包括参数部分）
        String[] urls = {
                "http://qmyx.huafacrm.com/state.html",
                "https://qmyx-sit.huafacrm.com/state.html",
                "https://qmyx-uat.huafacrm.com/state.html",
                "https://rushi.huafamarkting.com/h5/redirect",
                "https://abc.huafamarkting.com/state.html?param=value",
                "https://open.weixin.qq.com/connect/oauth2/authorize?appid=123&redirect_uri=https://example.com"
        };

        for (String url : urls) {
            boolean isWhitelisted = isWhitelisted(url);
            System.out.println(url + ": " + isWhitelisted);
        }

    }
}
